#Android boot partition for start up script
#disable SELinux

#check for needed programs
if [ ! -f "/usr/bin/abootimg" ] || [ ! -f "/usr/bin/fastboot" ] || [ ! -f "/usr/bin/adb" ]
then
  apt-get install abootimg android-tools-fastboot android-tools-adb -y
fi

#get image from android device 
#connect through adb to recovery (TWRP or Clockwork, etc)
adb shell

#find boot partition
adb shell ls -l /dev/block/bootdevice/by-name/boot|tr ' ' '\n'|grep mmc

#create img
#dd if=/dev/block/mmcblk0p31 of=/tmp/boot.img bs=4096
adb pull /dev/block/mmcblk0p31 boot.img

#check file 
file boot.img

#extract image
abootimg -x boot.img

##"updating bootimg.cfg" to disable SELinux
#add 'androidboot.selinux=permissive' to the end of the 'cmdline'
#example -- "https://raw.githubusercontent.com/metalx1000/Moto-G-root-tricks/master/config/bootimg.cfg"
sed -i '${s/$/ androidboot.selinux=permissive/}' bootimg.cfg

#repackage
#####abootimg --create boot2.img -f bootimg.cfg -k zImage -r initrd.img### this didn't work
#Update image
abootimg -u boot.img -f bootimg.cfg

#test it out
sudo fastboot boot boot2.img

#Flash it
sudo fastboot flash boot boot.img

#reboot
sudo fastboot reboot